package com.jstyle.beatecg.util;


import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.text.TextUtils;
import android.util.DisplayMetrics;


import com.jstyle.beatecg.app.MyApplication;

import java.util.Locale;

/**
 * 语言帮助类
 */
public class LanguageHelp {

    /**
     * 当前语言是否是英语
     * @return
     */
    public  static  Boolean isEnglish(){
        String sta = SharePreferenceUtils.getSpString(SharePreferenceUtils.KEY_Language);
     if(null==sta){
         return  false;//为空默认为中文
     } else if(sta.contains("en")) {
         return  true; }
     else{
         return  false; }
    }


    public static void changeAppLanguage(Context context) {

        String sta = SharePreferenceUtils.getSpString(SharePreferenceUtils.KEY_Language);
        // 本地语言设置
        Locale locale = context.getResources().getConfiguration().locale;
        String language = locale.getLanguage();
        Locale myLocale = new Locale(TextUtils.isEmpty(sta) ? language : sta);
        Resources res = context.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = myLocale;
        res.updateConfiguration(conf, dm);
    }

    /**
     * 判断当前系统语言是否为中文
     * @return
     */
    public static boolean isZh() {
        Locale locale = MyApplication.context.getResources().getConfiguration().locale;
        String language = locale.getLanguage();
        if (language.endsWith("zh"))
            return true;
        else
            return false;
    }

}
